package com.hgxd.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hgxd.annotation.OperationLogAnnotation;
import com.hgxd.entity.pojo.OperateLog;
import com.hgxd.entity.vo.pagevo.OperateLogPageVo;
import com.hgxd.result.Result;
import com.hgxd.service.OperateLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 操作日志表
 *
 * @author fsd
 * @since 2023-10-18
 */
@Api(tags = "操作日志管理")
@RestController
@RequestMapping("/api/operateLog")
@CrossOrigin
public class OperateLogController {

    @Resource(name = "operateLogServiceImpl")
    private OperateLogService operateLogService;

    /**
     * 分页模糊查询
     * @param operateLogPageVo
     * @return
     */
    @PostMapping("/get/page")
    @ApiOperation(value = "分页模糊查询", notes = "分页模糊查询")
    @ApiImplicitParam(name = "operateLogPageVo", value = "分页工具类")
    @OperationLogAnnotation(operModule = "操作日志管理-分页模糊查询",operType = "分页模糊查询",operContent = "分页模糊查询操作日志")
    public Result<Page<OperateLog>> findPage(@RequestBody OperateLogPageVo operateLogPageVo) {
        LambdaQueryWrapper<OperateLog> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper
                .eq(!"".equals(operateLogPageVo.getUsername()),OperateLog::getUserName,operateLogPageVo.getUsername())
                .between(operateLogPageVo.getBeginTime()!=null&&operateLogPageVo.getEndingTime()!=null
                ,OperateLog::getDate,operateLogPageVo.getBeginTime(),operateLogPageVo.getEndingTime())
                .orderByDesc(OperateLog::getId);

        return Result.ok(operateLogService.page(new Page<>(operateLogPageVo.getPageNum(),operateLogPageVo.getPageSize()),queryWrapper));
    }
}

